<template>

    <table class="table table-bordered">
        <tr>
            <th>房号名称</th>
            <th>
                <input  type="text" v-model="tianjia1.hname">
            </th>
        </tr>
        <tr>
            <th>排序</th>
            <th>
                <input  type="text" v-model="tianjia1.paiXu">
            </th>
        </tr>
        <tr>
            <th>备注</th>
            <th>
                <input  type="text" v-model="tianjia1.beiZhu">
            </th>
        </tr>
        <tr>
            <th>状态</th>
            <th>
                <input  type="radio" :value="true" v-model="tianjia1.state">上架
                <input  type="radio" :value="false"  v-model="tianjia1.state">下架
            </th>
        </tr>

        <tr>
            <th>


            </th>
            <th>
                <button class="btn btn-success" @click="tianjia"> 添加</button>
            </th>
        </tr>
      




</table>




</template>




<script setup lang="ts">


import { ref } from 'vue';

import axios from 'axios';

const tianjia1 =ref({

    "hid": 0,
  "hname": "",
  "paiXu": 0,
  "beiZhu": "",
  "state": "",
  "isDel": true


})


const tianjia=()=>{

        if(tianjia1.value.hname=="")
        {
            alert('姓名不能为空')
            return ;
        }

        if((isNaN(tianjia1.value.paiXu)))
        {
                alert('排序序号只能是数字')
                return ;
        }
        
        if(tianjia1.value.paiXu==0)
        {
            alert('排序不能为0')
            return ;
        }

        
        if(tianjia1.value.beiZhu=="")
        {
            alert('备注不能为空')
            return ;
        }

        
        if(tianjia1.value.state=="")
        {
            alert('请选择状态')
            return ;
        }


    axios.post('https://localhost:7039/api/User/AddHao',tianjia1.value).then(res=>{
        if(res.data==-1)
    {
        alert('姓名存在')
    }
    else if(res.data>0)
    {
        alert('添加成功')
    }
    else
    {
        alert('添加失败')
    }
    })
}



</script>